<template>
  <div id="loginIndx">
    <div class="loginBox">
      <h1 class="title">登录</h1>
      <Form ref="user" :model="user" inline>
        <!-- 账号 -->
        <FormItem>
          <Input type="text" v-model="user.username" placeholder="请输入用户名">
            <Icon type="ios-person-outline" slot="prepend"></Icon>
          </Input>
        </FormItem>

        <!-- 密码 -->
        <FormItem>
          <Input
            type="password"
            v-model="user.password"
            placeholder="请输入密码"
          >
            <Icon type="ios-lock-outline" slot="prepend"></Icon>
          </Input>
        </FormItem>

        <br />

        <!-- 登录按钮 -->
        <FormItem>
          <Button type="primary" @click="onLogin('user')">登录</Button>
        </FormItem>
      </Form>
    </div>
  </div>
</template>

<script>
// 登录
import { adminLogin } from '@/api/user'
export default {
  name: 'loginIndx',
  components: {},
  props: {},
  data () {
    return {
      user: {
        username: 'admin1',
        password: '123456'
      }
    }
  },
  computed: {},
  watch: {},
  created () { },
  mounted () { },
  methods: {
    // 登录
    async onLogin () {
      const { data } = await adminLogin(this.user)
      if (data.code === 201) {
        this.$store.commit('changeUser', data.userInfo)
        this.$store.commit('changeUsername', this.user.username)
        this.$router.push('/')
        this.$Message.success(data.msg)
        return
      }
      this.$Message.error(data.msg)
    }
  }
}
</script>

<style lang='less' scoped>
#loginIndx {
  position: fixed;
  top: 0px;
  right: 0px;
  bottom: 0px;
  left: 0px;
  background: skyblue;
  .loginBox {
    width: 450px;
    height: 350px;
    background: #fff;
    position: fixed;
    top: 0px;
    right: 0px;
    bottom: 0px;
    left: 0px;
    margin: auto;
    padding: 40px;
    box-sizing: border-box;
    .title {
      text-align: center;
      padding-bottom: 30px;
    }
    .ivu-input-wrapper,
    .ivu-form-item {
      width: 100%;
    }
    .ivu-btn {
      width: 100%;
    }
  }
}
</style>
